
export const locationMixin = {
	data(){
		return {
			locationAddress: '',
		}
	},
	created(){
		// #ifndef H5
		this.getRegeo();
		// #endif		
	},
	methods:{
		getRegeo() {  
			let that = this
		    that.amap.getRegeo({  
		        success: (data) => {  
					let xaddress = data[0].regeocodeData.addressComponent.city+ data[0].regeocodeData.addressComponent.district
					uni.setStorageSync('locationData',{address:data[0].regeocodeData.formatted_address,adcode:data[0].regeocodeData.pois[0].name})
					xaddress = xaddress.replace('市','')
					let arr = xaddress.split('')
					arr.splice(2,0,',')
					let a = arr.join('')
					xaddress = a.replace(',','-')
					//console.log("adress",xaddress)
					this.locationAddress = xaddress
		        }  
		    });  
		},
		chooseLocation: function () {
			let that = this;
			uni.chooseLocation({
				success: (res) => {
					that.getLaLoAdderss(res.latitude,res.longitude);
				}
			})
		},
		//逆解析
		getLaLoAdderss(latitude,longitude){
			let that = this
			that.amap.getRegeo({
				location:`${longitude},${latitude}`,
			    success: (data) => {  
					console.log("ad",data)
					let xaddress = data[0].regeocodeData.addressComponent.city+ data[0].regeocodeData.addressComponent.district
					uni.setStorageSync('locationData',{address:data[0].regeocodeData.formatted_address,adcode:data[0].regeocodeData.pois[0].name})
					xaddress = xaddress.replace('市','')
					let arr = xaddress.split('')
					arr.splice(2,0,',')
					xaddress = arr.join('')
			        this.locationAddress =xaddress
			    },
				fail:function(err){
					console.log("err",err)
				}
			}); 
		}
	}
}


export const selectlocationMixin = {
	data(){
		return {
			locationAddress: '',
		}
	},
	methods:{
		chooseLocation: function () {
			let that = this;
			uni.chooseLocation({
				success: (res) => {
					that.form.longitude= res.longitude //经度
					that.form.latitude =res.latitude //纬度
					that.getLaLoAdderss(res.latitude,res.longitude);
				}
			})
		},
		//逆解析
		getLaLoAdderss(latitude,longitude){
			let that = this
			that.amap.getRegeo({
				location:`${longitude},${latitude}`,
			    success: (data) => {  
			       that.address =data[0].regeocodeData.formatted_address; 
				   that.form.address = data[0].regeocodeData.formatted_address; 
				   //console.log("that",that.form)
			    },
				fail:function(err){
					console.log("err",err)
				}
			}); 
		}
	}
}